<?php

// module/Site/src/Album/Controller/AlbumController.php:

namespace Registration\Controller;

use Registration\Model\Position;
use Registration\Model\PositionTable;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class ApiController extends AbstractActionController {

    protected $positionTable;

    private function getPositionTable() {
        if (!$this->positionTable) {
            $sm = $this->getServiceLocator();
            $this->positionTable = $sm->get('Registration\Model\PositionTable');
        }
        return $this->positionTable;
    }

    public function indexAction() {
        return $this->redirect()->toRoute('registration', array(
                            'action' => 'index'
                        ));
        $view = new ViewModel(array('title' => 'Api page'));
        $view->setTerminal(true);
        return $view;
    }

    public function testAction() {
        $id = (int) $this->params()->fromRoute('position', 0);
        $id = $id;
        $view = new ViewModel(
                        array('title' => 'Test page',
                            'position' => $id,
                        )
        );
        $view->setTerminal(true);
        return $view;
    }
    
    public function statusAction() {
        $id = (int) $this->params()->fromRoute('position', 0);
        $positions = $this->getPositionTable()->getPosition($id);
        $view = new ViewModel(
                        array('title' => 'Test page',
                            'status' => $positions->status,
                        )
        );
        $view->setTerminal(true);
        return $view;
    }
}
